#ifndef _UTIL_HPP
#define _UTIL_HPP

uint64_t startTime, endTime;


void tt(bool s, char *str);
void showStack(TaskHandle_t t);
void sysUtil();


// #define LOG_COLOR_YELLOW "\033[40;33m"
// #define LOG_COLOR_RED "\033[40;31m"
// #define LOG_COLOR_BLUE "\033[40;36m"
// #define LOG_COLOR_PURPLE "\033[40;35m"
// #define LOG_COLOR_RESET "\033[0m"


void showStack(TaskHandle_t t) {
	#ifdef CONFIG_MODE
		UBaseType_t cStack;
		char *taskTag = pcTaskGetName(t);
		while(1)
		{
			cStack = uxTaskGetStackHighWaterMark(t);
			printf("%s Stack = %d",taskTag, cStack);
			vTaskDelay(pdMS_TO_TICKS(1000));
		}
	#endif
}

uint64_t getTimeMs() {
	struct timeval tv_now;
	gettimeofday(&tv_now, NULL);
	return (int64_t)tv_now.tv_sec * 1000L + (int64_t)tv_now.tv_usec;
}

uint64_t getTimeUs() {
	struct timeval tv_now;
	gettimeofday(&tv_now, NULL);
	return (int64_t)tv_now.tv_sec * 1000000L + (int64_t)tv_now.tv_usec;
}

void tt(bool s, char *str) {
	if(!s)
	{
		endTime = 0;
		printf("TEST: %s\n", str);
		startTime = getTimeUs();
	}
	else if(s)
	{
		endTime = getTimeUs();
		printf("\033[40;33mstart = %lld, end = %lld, diff = %lld\033[0m\n", startTime, endTime, endTime - startTime);
	}
}



#endif